<?php

namespace app\api\controller;

/**
 * ============================================================================
 * DSKMS多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 评论控制器
 */
class  Memberevaluate extends MobileMember
{
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
    }

    /**
     * @api {POST} api/Memberevaluate/get_goodsevallist 获取当前用户的所有商品评论列表
     * @apiVersion 1.0.0
     * @apiGroup Memberevaluate
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {String} per_page 每页显示数量
     * @apiParam {String} page 当前页数
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object[]} result.goodsevallist  评论列表
     * @apiSuccess {Int} result.goodsevallist.geval_addtime  评论时间
     * @apiSuccess {Int} result.goodsevallist.geval_content  评论内容
     * @apiSuccess {Int} result.goodsevallist.geval_explain  评论回复
     * @apiSuccess {Int} result.goodsevallist.geval_frommemberid  评论用户ID
     * @apiSuccess {Int} result.goodsevallist.geval_frommembername  评论用户名称
     * @apiSuccess {Int} result.goodsevallist.geval_goodsid  评论商品ID
     * @apiSuccess {Int} result.goodsevallist.geval_goodsimage  评论商品图片
     * @apiSuccess {Int} result.goodsevallist.geval_goodsname  评论商品名称
     * @apiSuccess {Int} result.goodsevallist.geval_goodsprice  评论商品价格
     * @apiSuccess {Int} result.goodsevallist.geval_id  评论ID
     * @apiSuccess {Int} result.goodsevallist.geval_image  评论晒图
     * @apiSuccess {Int} result.goodsevallist.geval_isanonymous  是否匿名 0否1是
     * @apiSuccess {Int} result.goodsevallist.geval_ordergoodsid  订单商品ID
     * @apiSuccess {Int} result.goodsevallist.geval_orderid  订单ID
     * @apiSuccess {Int} result.goodsevallist.geval_orderno  订单编号
     * @apiSuccess {Int} result.goodsevallist.geval_remark  管理员对评价的处理备注
     * @apiSuccess {Int} result.goodsevallist.geval_scores  评分
     * @apiSuccess {Int} result.goodsevallist.geval_state  评论状态 0为正常 1为禁止显示
     * @apiSuccess {Int} result.goodsevallist.geval_storeid  店铺ID
     * @apiSuccess {Int} result.goodsevallist.geval_storename  店铺名称
     * @apiSuccess {Int} result.page_total  总页数
     * @apiSuccess {Boolean} result.hasmore  是否有更多 true是false否
     */
    public function get_goodsevallist() {
        $evaluategoods_model = model('evaluategoods');
        $condition = array();
        $condition[] = array('geval_frommemberid','=',$this->member_info['member_id']);
        $goodsevallist = $evaluategoods_model->getEvaluategoodsList($condition, 5, 'geval_id desc');
        foreach ($goodsevallist as $key => $goodseval) {
            $goodsevallist[$key]['geval_goodsimage'] = goods_cthumb($goodseval['geval_goodsimage'],270);
        }
        $result = array_merge(array('goodsevallist' => $goodsevallist), mobile_page($evaluategoods_model->page_info));
        ds_json_encode(10000, '操作成功！', $result);
    }
    /**
     * @api {POST} api/Memberevaluate/save 评论列表
     * @apiVersion 1.0.0
     * @apiGroup Memberevaluate
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} order_id 订单号
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     */
    public function index()
    {
        $order_id = intval(input('param.order_id'));
        $return = model('memberevaluate','logic')->validation($order_id, $this->member_info['member_id']);
        if (isset($return['state'])) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);

        $store = array();
        $store['store_id'] = $store_info['store_id'];
        $store['store_name'] = $store_info['store_name'];
        ds_json_encode(10000,'',array('store_info' => $store, 'order_goods' => $order_goods));
    }

    /**
     * @api {POST} api/Memberevaluate/save 评论保存
     * @apiVersion 1.0.0
     * @apiGroup Memberevaluate
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} order_id 订单号
     * @apiParam {Array} goods 订单商品rec_id为键的含score商品评分、comment评论、evaluate_image晒图、anony匿名的对象数组
     * @apiParam {Int} store_desccredit 机构描述评分
     * @apiParam {Int} store_servicecredit 机构服务评分
     * @apiParam {Int} store_deliverycredit 机构配送评分
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     */
    public function save()
    {
        $order_id = intval(input('post.order_id'));
        $return = model('memberevaluate','logic')->validation($order_id, $this->member_info['member_id']);
        if (isset($return['state'])) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);
        $return = model('memberevaluate','logic')->saveorderevaluate( $order_info, $store_info, $order_goods, $this->member_info['member_id'], $this->member_info['member_name']);

        if ($return == true) {
            ds_json_encode(10000,'评价成功');
        }
        else {
            ds_json_encode(10001,'评价失败');
        }
    }

    /**
     * 追评
     */
    public function again()
    {
        $order_id = intval(input('param.order_id'));
        $return = model('memberevaluate','logic')->validationAgain($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);
        $store = array();
        $store['store_id'] = $store_info['store_id'];
        $store['store_name'] = $store_info['store_name'];

        ds_json_encode(10000,'',array('store_info' => $store, 'evaluate_goods' => $evaluate_goods));
    }

    /**
     * 追加评价保存
     */
    public function save_again()
    {
        $order_id = intval(input('post.order_id'));
        $return = model('memberevaluate','logic')->validationAgain($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);

        $return = model('memberevaluate','logic')->saveAgain(input('post.'), $order_info, $evaluate_goods);
        if (!$return['state']) {
            ds_json_encode(10000,'',$return['msg']);
        }
        else {
            ds_json_encode(10001,'失败');
        }
    }


    /**
     * @api {POST} api/Memberevaluate/vr 虚拟订单评价
     * @apiVersion 1.0.0
     * @apiGroup Memberevaluate
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} order_id 订单号
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object} result.order_info  订单信息 （返回字段参考vrorder）
     */
    public function vr()
    {
        $order_id = intval(input('param.order_id'));
        $return = model('memberevaluate','logic')->validationVr($order_id, $this->member_info['member_id']);
        if (isset($return['state'])) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);
        ds_json_encode(10000,'',array('order_info' => $order_info));
    }

    /**
     * @api {POST} api/Memberevaluate/save_vr 虚拟订单评价保存
     * @apiVersion 1.0.0
     * @apiGroup Memberevaluate
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} order_id 订单号
     * @apiParam {Array} goods 订单商品rec_id为键的含score商品评分、comment评论、evaluate_image晒图、anony匿名的对象数组
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     */
    public function save_vr()
    {
        $order_id = intval(input('post.order_id'));
        $return = model('memberevaluate','logic')->validationVr($order_id, $this->member_info['member_id']);
        if (isset($return['state'])) {
            ds_json_encode(10001,$return['msg']);
        }
        extract($return['data']);

        $return = model('memberevaluate','logic')->saveVr(input('post.'),$order_info, $store_info, array($order_info), $this->member_info['member_id'], $this->member_info['member_name']);
        if (!$return['state']) {
            ds_json_encode(10000,'',$return['msg']);
        }
        else {
            ds_json_encode(10001,'失败');
        }
    }
}